package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.xml.stream.events.Comment;

public class CommentDAO {
private Connection conn;

    public CommentDAO(Connection conn) {
        this.conn = conn;
    }

    public boolean addComment(Comment comment) {
        String sql = "INSERT INTO comments (post_id, content) VALUES (?, ?)";
        try {
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, comment.getPostId());
            pstmt.setString(2, comment.getContent());
            int rowsAffected = pstmt.executeUpdate();
            return rowsAffected > 0;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    // 其他方法，如查询评论、更新评论信息等
}